package com.my.algorithmlearning.leetcode;

import org.springframework.util.Assert;

/**
 * @ClassName Medium_11_MaxArea
 * @Description Medium_11_MaxArea
 * @Author wanghaiwei
 * @Date 2023/2/2 17:07
 */
public class Medium_11_MaxArea {
    public int maxArea(int[] height) {
        int maxArea = 0;
        int i = 0;
        int j = height.length - 1;
        while (i < j) {
            int currArea = Math.min(height[i], height[j]) * (j - i);
            maxArea = Math.max(currArea, maxArea);
            if (height[i] <= height[j]) {
                i++;
            } else {
                j--;
            }
        }
        return maxArea;
    }

    public static void main(String[] args) {
        Medium_11_MaxArea solution = new Medium_11_MaxArea();
        int result = solution.maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7});
        Assert.isTrue(49 == result, "[1,8,6,2,5,4,8,3,7]计算错误，预期：49，实际：" + result);
        result = solution.maxArea(new int[]{1, 1});
        Assert.isTrue(1 == result, "[1,1]计算错误，预期：1，实际：" + result);
    }
}
